package com.liangfeng.breezebrowser.browsermvp.view.webview;

import android.graphics.Bitmap;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.apkfuns.logutils.LogUtils;

import io.realm.Realm;

/**
 * Created by mozhifeng on 2017/5/26.
 */

public class BrowserClient extends WebViewClient {

    //    private String browHistory;
    private Realm realm;

    public BrowserClient(Realm realm) {
        this.realm = realm;
    }

//    @Override
//    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
//        view.loadUrl(view, request.getUrl().toString());
//        return super.shouldOverrideUrlLoading(view, request);
//    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return super.shouldOverrideUrlLoading(view, url);
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        // 开始加载网页时处理 如：显示"加载提示" 的加载对话框
        LogUtils.e("开始加载网页");
        LogUtils.e(url);

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        // 网页加载完成时处理  如：让 加载对话框 消失
    }

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
        //加载网页失败时处理 如：提示失败，或显示新的界面
        LogUtils.e("加载网页失败");

    }

}
